package com.tmxk.api.days01.zjq;

import java.util.ArrayList;

/**
 *
 */
public class ArrayListDemo01 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        Dog dog1 = new Dog("11",3);
        arrayList.add(dog1);
        arrayList.add(new Dog("小花",7));
        arrayList.add(new Dog("花花",1));
        arrayList.add(new Dog("小黑",9));
        arrayList.add(new Dog("小白",5));
        arrayList.add(new Dog("汪汪",3));


//        Dog dog = (Dog) arrayList.get(2);
//        System.out.println(dog);

        for (Object obj : arrayList){
            Dog d = (Dog) obj;
            if ("11".equals(d.getName())) {
                System.out.println("存在该元素");
            }
        }

//        定义一个标识符，用来标识定义的元素是否存在，默认false不存在
        System.out.println("遍历元素");
        boolean b = false;
        for (int i = 0; i <arrayList.size() ; i++) {
            Dog d = (Dog)arrayList.get(i);
            if ("花花".equals(d.getName())){
              b = arrayList.remove(d);
            }
        }
        System.out.println(b==true ? "删除成功":"删除失败");

        for (int i = 0; i <arrayList.size() ; i++) {
            System.out.println(arrayList.get(i));
        }
    }

}
